package com.owbtgad.common.utils;

import android.app.Application;

import com.tencent.mmkv.MMKV;


/**
 * SharedPreferences工具类
 * 保存 夜间模式
 * Created by tomchen on 2/3/16.
 */
public class PrefUtils {

    private static final String TOKEN = "token";
    private static final String USER_NAME = "user_name";
    private static final String START_IMG = "start_img";
    private static final String VERSION_NAME = "versionName";
    private static final String VERSION_NAME_TIME = "versionNameTime";
    private static final String GUIDE_PAGE = "guide_page";//引导页
    private static final String GUIDE_PAGE2 = "guide_page2";//引导页
    private static final String SIG_IN_PROTOCOL = "sign_in_protocol";//注册协议
    private static final String BOOK_PHONE_TIME = "book_phone_time";//上传时间
    private static final String APP_UUID = "appUuid";//appuuid
    private static final String USER_ID = "user_Id";
    private static final String USER_PHONE = "user_phone";
    private static final String AUTH_CODE = "authCode";
    private static final String PermissionDescription = "PermissionDescription";
    private static Application sApplication;

    public static void init(Application application) {
        sApplication = application;
    }

    private static MMKV getSharedPreferences() {
        return MMKV.defaultMMKV();
    }

    /**
     * 账号
     *
     * @return
     */
    public static String getUserId() {
        return getSharedPreferences().getString(USER_ID, "");
    }

    /**
     * 账号
     */
    public static void setUserId(String userId) {
        getSharedPreferences().putString(USER_ID, userId);
    }

    /**
     * @return
     */
    public static String getUserPhone() {
        return getSharedPreferences().getString(USER_PHONE, "");
    }

    /**
     *
     */
    public static void setUserPhone(String userPhone) {
        getSharedPreferences().putString(USER_PHONE, userPhone);
    }


    /**
     * uuid
     *
     * @return
     */
    public static String getAppUuid() {
        return getSharedPreferences().getString(APP_UUID, "");
    }

    /**
     * uuid
     */
    public static void setAppUuid(String appUuid) {
        getSharedPreferences().putString(APP_UUID, appUuid);
    }

    /**
     * 版本
     *
     * @return
     */
    public static String getVersionName() {
        return getSharedPreferences().getString(VERSION_NAME, "");
    }

    /**
     * 版本
     *
     * @param versionName
     */
    public static void setVersionName(String versionName) {
        getSharedPreferences().putString(VERSION_NAME, versionName);
        setVersionNameTime();
    }

    /**
     * 版本时间
     *
     * @return
     */
    public static long getVersionNameTime() {
        return getSharedPreferences().getLong(VERSION_NAME_TIME, 0);
    }

    /**
     * 版本时间
     *
     * @param versionName
     */
    public static void setVersionNameTime() {
//        Calendar calendar7 = DateTime.beforeNDays(null,2);
        getSharedPreferences().putLong(VERSION_NAME_TIME, System.currentTimeMillis());
    }


    /**
     * 加密串
     *
     * @return
     */
    public static String getAuthCode() {
        return getSharedPreferences().getString(AUTH_CODE, "");
    }

    /**
     * 加密串
     */
    public static void setAuthCode(String authCode) {
        getSharedPreferences().putString(AUTH_CODE, authCode);
    }

    /**
     * 加密串
     *
     * @return
     */
    public static long getBookPhoneTime() {
        return getSharedPreferences().getLong(BOOK_PHONE_TIME, 0);
    }

    /**
     * 加密串
     */
    public static void setBookPhoneTime(long time) {
        getSharedPreferences().putLong(BOOK_PHONE_TIME, time);
    }

    /**
     * token
     *
     * @return
     */
    public static String getToken() {
        return getSharedPreferences().getString(TOKEN, "");
    }

    /**
     * token
     *
     * @param token
     */
    public static void setToken(String token) {
        getSharedPreferences().putString(TOKEN, token);
    }

    /**
     * userName
     *
     * @return
     */
    public static String getUserName() {
        return getSharedPreferences().getString(USER_NAME, "notLogin");
    }

    /**
     * userName
     *
     * @param token
     */
    public static void setUserName(String token) {
        getSharedPreferences().putString(USER_NAME, token);
    }

    /**
     * 启动页
     *
     * @return
     */
    public static String getStartImg() {
        return getSharedPreferences().getString(START_IMG, "");
    }

    /**
     * 启动页
     *
     * @param token
     */
    public static void setStartImg(String token) {
        getSharedPreferences().putString(START_IMG, token);
    }

    /**
     * 权限提示dialog
     *
     * @return
     */
    public static boolean isPermissionDescription() {
        return getSharedPreferences().getBoolean(PermissionDescription, true);
    }

    /**
     * 权限提示dialog
     *
     * @param b
     */
    public static void setPermissionDescription(boolean b) {
        getSharedPreferences().putBoolean(PermissionDescription, b);
    }


    /**
     * 注册协议弹框
     *
     * @return
     */
    public static boolean isSigInProtocol() {
        return getSharedPreferences().getBoolean(SIG_IN_PROTOCOL, true);
    }

    /**
     * @param isSaveNetMode true 注册协议弹框 展示
     */
    public static void setSigInProtocol(boolean isSaveNetMode) {
        getSharedPreferences().putBoolean(SIG_IN_PROTOCOL, isSaveNetMode);
    }


    public static void putString(String key, String value) {
        getSharedPreferences().putString(key, value);
    }

    public static String getString(String key) {
        return getSharedPreferences().getString(key, "");
    }
}